import request from "@/utils/request";
import { useUserStore } from '@/stores/user';
// 获取 token 的工具函数  
const getToken = () => {
  const userStore = useUserStore();
  return userStore.token;
};
//获取推文列表接口

export const getTweetList = (params) =>
  request.get("/posts/list", params, {
    headers: {
      'Authorization': getToken()
    }
  });
//获取推文详情接口
export const getTweetDetail = (postId) => request.post("/posts/postDetails", null, {
  params: { postId }
});
//获取推文评论
export const getTweetComments = (postId) => request.post("/posts/comments", null, {
  params: { postId }
})
//发表评论接口
export const postComment = (postdata) => {
  return request({
    url: '/posts/addComment',
    method: 'post',
    data: postdata
  })
}
// export const getTweetDetail = (id) =>
//   request.post("/posts/postDetails", { postid: id });

//获取作者信息接口

export const getAuthorInfo = (params) => request.get("/users/info", { params });

//发布推文
export const postTweet = (FormData) => {
  return request({
    url: '/posts/addPost',
    method: 'post',
    data: FormData,
    headers: {
      'Authorization': getToken(),
      'Content-Type': 'multipart/form-data',
    }
  })
}
//点赞/取消点赞接口
export const likeTweet = (postId) => {
  return request({
    url: '/posts/collect',
    method: 'post',
    params: { postId },
    headers: {
      'Authorization': getToken(),
    }
  })
}
//判断是否点赞
export const isLikeTweet = (postId) => {
  return request({
    url: '/posts/isCollected',
    method: 'get',
    params: { postId },
    headers: {
      'Authorization': getToken(),
    }
  })
}